package com.zsck.pos.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chinaums.commoncheck.R;
import com.zsck.pos.bean.Bill;
import com.zsck.pos.bean.Record;

import java.math.BigDecimal;
import java.util.List;


public class BillAdapter extends BaseAdapter {
    private Context mContext;
    private List<Bill> mRecords;
    private String keyword;

    public BillAdapter(Context context, List<Bill> records,String keyword){
        this.mContext = context;
        this.mRecords = records;
        this.keyword = keyword;
    }

    @Override
    public int getCount() {
        return mRecords.size();
    }

    @Override
    public Bill getItem(int position) {
        return mRecords.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(mContext, R.layout.item_bill,null);
            holder = new ViewHolder();
            holder.tvName = convertView.findViewById(R.id.tv_name);
            holder.tvStatus = convertView.findViewById(R.id.tv_status);
            holder.tvProject = convertView.findViewById(R.id.tv_project);
            holder.tvMoney = convertView.findViewById(R.id.tv_money);
            holder.tvCost = convertView.findViewById(R.id.tv_cost);
            holder.llWho = convertView.findViewById(R.id.ll_who);
            holder.tvWho = convertView.findViewById(R.id.tv_who);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        if(position == 0){
            holder.llWho.setVisibility(View.VISIBLE);
            holder.tvWho.setText(keyword);
        }else{
            holder.llWho.setVisibility(View.GONE);
        }

        Bill item = getItem(position);
        holder.tvName.setText(item.getRoomName());
        //holder.tvStatus.setText(item.getStatus());
        holder.tvProject.setText(item.getProjectName());
        holder.tvCost.setText(item.getMonth());
        BigDecimal d1 = new BigDecimal(Double.toString(item.getAmount()));
        holder.tvMoney.setText(d1 + "");
        //int color = Color.parseColor("支付成功".equals(item.getStatus()) ? "#F0861B" : "#999999");
        //holder.tvMoney.setTextColor(color);
        //holder.tvStatus.setTextColor(color);

        String status = "";
        if("unReceive".equals(item.getBillStatus())){
            status = "未缴纳";
        }else if("halfReceive".equals(item.getBillStatus())){
            status = "部分缴纳";
        }
        holder.tvStatus.setText(status);
        return convertView;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    static class ViewHolder{
        TextView tvName;
        TextView tvStatus;
        TextView tvProject;
        TextView tvMoney;
        TextView tvCost;
        TextView tvIn;
        LinearLayout llWho;
        TextView tvWho;
    }
}
